package arithmetic2.day08;

import java.util.Arrays;

/*
    用贪心策略求解会议安排问题
 */
public class Greed01 implements Comparable<Greed01> {
    public int startTime;

    public int endTime;

    public Greed01(int startTime, int endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    @Override
    public int compareTo(Greed01 o) {
        return this.endTime - o.endTime;
    }

    public int greed(Greed01[] greeds) {
        int result = 0;
        Arrays.sort(greeds);
        int curTime = 0;
        for (Greed01 greed : greeds) {
            if (curTime < greed.startTime) {
                result++;
                curTime = greed.endTime;
            }
        }
        return result;
    }

}
